<script setup lang="ts">
import { ref } from 'vue'
import { broadcastScan } from './span'

const title = ref('测试')

const result = ref()

const openScan = () => {
  broadcastScan.triggerScan()
}

const spanCallback = (code) => {
  const parseData = code.trim()
  console.log('自定义扫描的结果回调函数:', parseData)
  result.value = parseData
}

onShow(() => {
  console.log('show')
  broadcastScan.start()
})

onHide(() => {
  console.log('hide')
  broadcastScan.stop()
})

onLoad(() => {
  console.log('load')
  broadcastScan.init(spanCallback)
})
</script>

<template>
  <view class="home-container">
    <view class="intro">广播名称：com.android.server.scannerservice.broadcast</view>
    <view class="intro">广播键值：scannerdata</view>

    <view class="intro">主动开始扫描广播：com.scan.onStartScan</view>
    <view class="intro">主动结束扫描广播：com.scan.onEndScan</view>

    <text class="intro">详见：</text>
    <br />

    <view>
      <view type="primary" @click="openScan">开始扫码</view>
    </view>

    <view class="result-container">
      {{ result }}
    </view>
  </view>
</template>

<style lang="less" scoped></style>
